HTTP服务器之 - http-server (NodeJs)

Sublime Text3 是一款非常优秀的跨平台编辑器,工欲善其事必先利其器,作为一名开发同学,这里简单记录下Sublime Text3的配置。
有时候我们需要搭建静态服务器,这时候http-server就可以帮到我们实现啦~

安装命令:

1
$ npm install -g http-server

运行命令:

切换到项目目录下

1
$ http-server [path] [options]

自定义命令

使用于package.json

1
2
3
"scripts": {
"start": "http-server -a 0.0.0.0 -p 8000",
}

如下例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"name": "webapp",
"version": "1.0.0",
"description": "this is a webapp",
"main": "index.js",
"scripts": {
"start": "http-server -a 0.0.0.0 -p 8000"
},
"author": "vincentDu",
"license": "ISC",
"directories": {
"test": "test"
}
}

1
2
cd 项目路径 //切换到项目下
npm start //启动命令

参数配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-p 端口号 (默认 8080)
-a IP 地址 (默认 0.0.0.0)
-d 显示目录列表 (默认 ‘True’)
-i 显示 autoIndex (默认 ‘True’)
-e or –ext 如果没有提供默认的文件扩展名(默认 ‘html’)
-s or –silent 禁止日志信息输出
–cors 启用 CORS via the Access-Control-Allow-Origin header
-o 在开始服务后打开浏览器
-c 为 cache-control max-age header 设置Cache time(秒) , e.g. -c10 for 10 seconds (defaults to ‘3600’). 禁用 caching, 则使用 -c-1.
-U 或 –utc 使用UTC time 格式化log消息
-P or –proxy Proxies all requests which can’t be resolved locally to the given url. e.g.: -P http://someurl.com
-S or –ssl 启用 https
-C or –cert ssl cert 文件路径 (default: cert.pem)
-K or –key Path to ssl key file (default: key.pem).
-r or –robots Provide a /robots.txt (whose content defaults to ‘User-agent: *\nDisallow: /‘)
-h or –help 打印以上列表并退出
vincentSea wechat
一颗稻草的价值,到底是多少呢?想知道的话,就订阅吧!